<template>
  <div>
    <el-dialog
      :title="obj.isadd ? '会员添加' : '会员编辑'"
      :visible.sync="obj.istrue"
      width="40%"
      @close="cancel()"
    >
      <span>
        <el-form ref="form" :model="form" label-width="80px">
          <el-form-item label="手机号">
            <el-input v-model="form.phone"></el-input>
          </el-form-item>
          <el-form-item label="昵称">
            <el-input v-model="form.nickname"></el-input>
          </el-form-item>
          <el-form-item label="密码">
            <el-input v-model="form.password" show-password></el-input>
          </el-form-item>
          <el-form-item label="状态">
            <el-switch
              v-model="form.status"
              :active-value="1"
              :inactive-value="2"
            ></el-switch>
          </el-form-item>
        </el-form>
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="edit" >修改</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
import {  memberinfo, memberedit } from "../../../requset/api";
import { successAlert, warningAlert } from "../../../util/alert.js";
export default {
  props: ["obj"],
  data() {
    return {
      form: {
        uid:"",
        nickname: "",
        phone: "",
        password: "",
        status: 1,
      },
    };
  },
  computed: {
    ...mapGetters({
      memberlist: "member/list",
    }),
  },
  methods: {
    ...mapActions({
      reqChangeMember: "member/reqChangeMember"
    }),
    emty() {
      this.form = {
        uid:"",
        nickname: "",
        phone: "",
        password: "",
        status: 1,
      };
    },
    cancel() {
      this.obj.istrue = false;
      this.obj.isadd = true;
      this.emty();
    },
    // submit() {
    //   useradd(this.form).then((res) => {
    //     if (res.data.code == 200) {
    //       successAlert(res.data.msg);
    //       this.cancel();
    //       this.reqChangeManage();
    //       this.reqChangeTotal();
    //     } else {
    //       warningAlert(res.data.msg);
    //     }
    //   });
    // },
    getone(uid) {
      memberinfo({ uid: uid }).then((res) => {
        this.form = res.data.list;
        this.form.password = "";
      });
    },
    edit() {
      memberedit(this.form).then((res) => {
        if (res.data.code == 200) {
          successAlert(res.data.msg);
          this.cancel();
          this.reqChangeMember();
        } else {
          warningAlert(res.data.msg);
        }
      });
    },
  },
  mounted() {
    this.reqChangeMember();
  },
};
</script>

<style lang="scss" scoped>
</style>